package com.itheima.controller;

import com.itheima.exception.BussinessException;
import com.itheima.exception.SystemException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice//用以标识当前类为Rest风格对应的异常处理器
public class ProjectExceptionAdvice {
    //处理当前服务器对应的异常类型
    @ExceptionHandler(SystemException.class)
    public Result doSystemException(SystemException ex){
        return new Result(ex.getCode(),null,ex.getMessage());
    }
    @ExceptionHandler(BussinessException.class)
    public Result doBussinessException(BussinessException ex){
        return new Result(ex.getCode(),null,ex.getMessage());
    }
    //统一处理所有的exception异常
    @ExceptionHandler(Exception.class)
    public Result doOtherException(Exception ex){

        return new Result(Code.SYSTEM_UNKNOW_ERR,null,"系统繁忙,稍后试");

    }


}
